﻿<UserControl x:Class="CAION2.Views.RecipesList_Page"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:controls="clr-namespace:CAION2.Controls"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:helpers="clr-namespace:CAION2.Helpers"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:models="clr-namespace:CAION2.Models"
             xmlns:mui="http://firstfloorsoftware.com/ModernUI"
             xmlns:resources="clr-namespace:CAION2.Properties"
             xmlns:viewModels="clr-namespace:CAION2.ViewModels"
             FontFamily="/Fonts/Marmelad-Regular.ttf#Marmelad"
             mc:Ignorable="d">

    <UserControl.Resources>
        <viewModels:RecipesListViewModel x:Key="ViewModels" />
        <viewModels:ItemTypeColorConverter x:Key="ItemTypeColor" />

        <DataTemplate x:Key="ProfessionTemplate" DataType="{x:Type models:CraftProfession}">
            <TextBlock Text="{Binding Path=Translate}" />
        </DataTemplate>

        <Style x:Key="RecipesListViewItem"
               BasedOn="{StaticResource {x:Type ListViewItem}}"
               TargetType="ListViewItem">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="ListViewItem">
                        <Grid>
                            <Border Name="Selection" Visibility="Collapsed" />

                            <GridViewRowPresenter HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}"
                                                  Content="{TemplateBinding ContentControl.Content}"
                                                  SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />

                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter TargetName="Selection" Property="Visibility" Value="Visible" />
                                <Setter TargetName="Selection" Property="Background" Value="{DynamicResource ItemBackgroundHover}" />
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextHover}" />
                            </Trigger>
                            <Trigger Property="IsSelected" Value="true">
                                <Setter TargetName="Selection" Property="Visibility" Value="Visible" />
                                <Setter TargetName="Selection" Property="Background" Value="{DynamicResource ItemBackgroundSelected}" />
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextSelected}" />
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="false">
                                <Setter Property="Foreground" Value="{DynamicResource ItemTextDisabled}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
            <Style.Triggers>
                <Trigger Property="IsSelected" Value="true">
                    <Setter Property="Foreground" Value="{DynamicResource ItemTextSelected}" />
                </Trigger>
            </Style.Triggers>
        </Style>


    </UserControl.Resources>


    <Grid DataContext="{Binding Source={StaticResource ViewModels}}" 
          Style="{StaticResource ContentRoot}">

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="320" />
            <ColumnDefinition MinWidth="430" />
            <ColumnDefinition MinWidth="430" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="50" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
            <RowDefinition Height="30" />
            <RowDefinition Height="10" />
        </Grid.RowDefinitions>

        <mui:ModernButton Content="{x:Static resources:Resources.RR_ToRecepture}" 
                          Grid.Column="2"
                          Grid.ColumnSpan="2"
                          VerticalAlignment="Top"
                          HorizontalAlignment="Right"
                          IconData="{StaticResource TreeIcon}"
                          Margin="{StaticResource HeaderMargin}"
                          IsEnabled="{Binding ToReceptureEnable}"
                          Command="{Binding CreateReceptuteCommand}"/>
        
        <ComboBox Grid.Row="0" 
                  Grid.Column="0" 
                  MinWidth="180"
                  MaxWidth="220"
                  Margin="0,0,0,0"
                  HorizontalAlignment="Left"
                  VerticalAlignment="Center"
                  ItemTemplate="{StaticResource ProfessionTemplate}"
                  ItemsSource="{Binding CraftProfessions}"
                  SelectedItem="{Binding SelectedProfession,
                                         Mode=TwoWay,
                                         UpdateSourceTrigger=PropertyChanged}"
                  ToolTip="{x:Static resources:Resources.RR_Profession}" />

        <controls:SearchTextBox Grid.Row="1" 
                                Grid.Column="0"
                                Margin="0,25,30,0"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Top"
                                BorderThickness="{Binding FilterErrorBorder}"
                                Text="{Binding FilterText,
                                               Mode=TwoWay,
                                               UpdateSourceTrigger=PropertyChanged}"
                                ToolTip="{x:Static resources:Resources.RR_Filter}"
                                Visibility="{Binding PageContentVisible}" />

        <mui:ModernButton Grid.Row="1" 
                          Grid.Column="0"
                          Margin="5,25,0,0"
                          HorizontalAlignment="Right"
                          Command="{Binding OpenExtendedFilterCommand}"
                          IconData="{StaticResource FilterIcon}"
                          ToolTip="{x:Static resources:Resources.RR_FilterEx}"
                          Visibility="{Binding PageContentVisible}" />
 
        <ListView Grid.Row="2" 
                  Grid.Column="0"
                  Margin="0,30,0,0"
                  HorizontalAlignment="Stretch"
                  VerticalAlignment="Stretch"
                  HorizontalContentAlignment="Stretch"
                  VerticalContentAlignment="Stretch"
                  AlternationCount="0"
                  IsSynchronizedWithCurrentItem="True"
                  ItemContainerStyle="{StaticResource RecipesListViewItem}"
                  ItemsSource="{Binding RecipesListView}"
                  ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                  SelectedItem="{Binding SelectedRecipe,
                                         Mode=TwoWay,
                                         UpdateSourceTrigger=PropertyChanged}"
                  SelectionMode="Single"
                  VirtualizingStackPanel.IsVirtualizing="True"
                  VirtualizingStackPanel.VirtualizationMode="Recycling"
                  Visibility="{Binding PageContentVisible}"
                  helpers:GridViewSort.AutoSort="True">

            <ListView.View>
                <GridView>
                    <GridView.Columns>

                        <GridViewColumn Width="10">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <Border Margin="-4,-4,-4,-4" Background="{Binding Path=Type, Converter={StaticResource ItemTypeColor}}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>

                        <GridViewColumn Width="190"
                                        Header="{x:Static resources:Resources.RR_ListViewHeaderName}"
                                        helpers:GridViewSort.PropertyExtendedName="RecipeLevel"
                                        helpers:GridViewSort.PropertyName="Translate">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="4,4,0,4"
                                               Text="{Binding Path=Translate}"
                                               TextWrapping="WrapWithOverflow" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>

                        <GridViewColumn Width="50"
                                        helpers:GridViewSort.PropertyExtendedName="CharacterLevel,Translate"
                                        helpers:GridViewSort.PropertyName="RecipeLevel">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center" Text="{Binding Path=RecipeLevel}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                            <GridViewColumn.Header>
                                <Path Grid.Column="1"
                                      Width="10"
                                      Height="10"
                                      Margin="0"
                                      HorizontalAlignment="Left"
                                      VerticalAlignment="Bottom"
                                      Data="{StaticResource RecipesIcon}"
                                      Fill="{DynamicResource ButtonText}"
                                      RenderTransformOrigin="0.5,0.5"
                                      Stretch="Uniform"
                                      ToolTip="{x:Static resources:Resources.RR_RecipesMinLevelTip}" />
                            </GridViewColumn.Header>
                        </GridViewColumn>

                        <GridViewColumn Width="50"
                                        helpers:GridViewSort.PropertyExtendedName="RecipeLevel"
                                        helpers:GridViewSort.PropertyName="CharacterLevel">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock HorizontalAlignment="Center" Text="{Binding Path=CharacterLevel}" />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                            <GridViewColumn.Header>
                                <Path Grid.Column="1"
                                      Width="10"
                                      Height="10"
                                      Margin="0"
                                      HorizontalAlignment="Left"
                                      VerticalAlignment="Bottom"
                                      Data="{StaticResource CharacterIcon}"
                                      Fill="{DynamicResource ButtonText}"
                                      RenderTransformOrigin="0.5,0.5"
                                      Stretch="Uniform"
                                      ToolTip="{x:Static resources:Resources.RR_CharacterMinLevelTip}" />
                            </GridViewColumn.Header>
                        </GridViewColumn>

                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>

        <TextBlock Grid.Row="3" 
                   Grid.Column="0"
                   VerticalAlignment="Bottom"
                   FontSize="12"
                   Foreground="{DynamicResource ItemTextDisabled}"
                   Text="{Binding RecipesListCount}" />


        <Border Grid.Row="1" 
                Grid.RowSpan="3"
                Grid.Column="1"
                Margin="40,0,0,0">
            <controls:ItemCard BorderBrush="{DynamicResource ModernButtonBorderDisabled}"
                               BorderThickness="1"
                               DataContext="{Binding Card1DataContext}" />
        </Border>


        <Border Grid.Row="1" 
                Grid.RowSpan="3"
                Grid.Column="2"
                Margin="10,0,0,0">
            <controls:ItemCard BorderBrush="{DynamicResource ModernButtonBorderDisabled}"
                               BorderThickness="1"
                               DataContext="{Binding Card2DataContext}" />
        </Border>

    </Grid>

</UserControl>
